<?php
!function_exists('adminmsg') && die('Forbidden');

class help{
	
	function doIt(){
		global $action;
		switch ($action){
			case 'add':
				$this->Add();
				break;
			case 'edit':
				$this->Edit();
				break;
			case 'show':
				$this->Show();
				break;
			case 'del':
				global $helpid;
				$this->del($helpid);
				break;
			default:
				$this->Show();
				break;
		}
	}
	
	function Show(){
		global $db,$basename;
		$help = array();
		$rs = $db->query("SELECT * FROM cms_help ORDER BY postdate DESC");
		while ($helpdb = $db->fetch_array($rs)) {
			$helpdb['postdate'] = get_date($helpdb['postdate']);
			$help[] = $helpdb;
		}
		require PrintEot('header');
		require PrintEot('ext_help');
		adminbottom();
	}
	
	function Add(){
		global $basename,$action,$step;
		if(!$step){
			$contentEdit = $this->Editor('content');
			require PrintEot('header');
			require PrintEot('ext_help');
			adminbottom();
		}elseif ($step==2){
			$this->Save();
			adminmsg('该帮助信息已经成功保存');
		}
	}
	
	function Edit(){
		global $db,$basename,$action,$step;
		if(!$step){
			@extract($db->get_one("SELECT * FROM cms_help WHERE helpid='$_GET[helpid]'"));
			$contentEdit = $this->Editor('content',$content);
			require PrintEot('header');
			require PrintEot('ext_help');
			adminbottom();
		}elseif ($step==2){
			$this->Save();
			adminmsg('帮助信息成功编辑');
		}		
	}
	
	function Editor($inputname,$Value='')
	{
		global $very;
		$height=250;
		$width=550;
		require_once(R_P.'require/fckeditor/fckeditor.php');
		$edit = new Fckeditor($inputname);
		$edit->Height = $height;
		$edit->Width = $width;
		$edit->ToolbarSet = 'Default';
		$edit->BaseSrc = $very['url'];
		$edit->BasePath = $edit->BaseSrc . '/require/fckeditor/';
		$edit->Value = $Value;
		$edit->BaseName = $GLOBALS['admin_file'];
		$Html = $edit->CreateHtml();
		return $Html;
	}
	
	function Save(){
		global $action,$db,$title,$content,$login_name,$timestamp;
		empty($title) && Showmsg('没有输入帮助信息的标题');
		empty($content) && Showmsg('没有输入帮助信息的内容');
		if($action=='add'){
			$sql = "INSERT INTO ";
		}else{
			$sql = "UPDATE ";
			global $helpid;
			$sqladd = "WHERE helpid='$helpid'";
		}
		$sql.="cms_help SET 
			title='$title',
			content='$content',
			author='$login_name',
			postdate='$timestamp'
			$sqladd
		";
		$db->update($sql);
	}
	
	function del($helpid){
		global $db;
		if(is_array($helpid)){
			$helpids = implode(',',$helpid);
			$db->update("DELETE FROM cms_help WHERE helpid IN($helpids)");
		}else{
			$helpid = (int)$helpid;
			$db->update("DELETE FROM cms_help WHERE helpid='$helpid'");
		}
		adminmsg('删除了帮助信息');
	}
}

$help = new help();
$help->doIt();
?>